//
//  ConnectOurViewController.m
//  GiftSay
//
//  Created by QQn1993 on 16/1/18.
//  Copyright © 2016年 liyinkai. All rights reserved.
//

#import "ConnectOurViewController.h"

@interface ConnectOurViewController ()

@property (nonatomic,strong) UITextView *text;

@end

@implementation ConnectOurViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.text = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight / 2)];
    self.text.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    [self.view addSubview:self.text];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(kWidth / 10 , kHeight / 2 + kHeight / 10, kWidth / 10 * 8, kHeight / 10);
    [btn setTitle:@"完成" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.layer.masksToBounds = YES;
    btn.layer.borderWidth = 2;
    btn.layer.cornerRadius = kHeight / 20;
    [btn addTarget:self action:@selector(endEdting) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    [self.view addSubview:btn];
    
    // Do any additional setup after loading the view.
}

- (void)endEdting
{
    [self showMessageView:@[@"15724530558",@"13804280497",@"18608713703"] title:@"反馈~" body:self.text.text];
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
    
    switch(result){
        caseMessageComposeResultSent:
            //信息传送成功
            break;
        caseMessageComposeResultFailed:
            //信息传送失败
            break;
        caseMessageComposeResultCancelled:
            //信息被用户取消传送
            break;
        default:
            break;
    }
}

-(void)showMessageView:(NSArray*)phones title:(NSString*)title body:(NSString*)body
{
    if([MFMessageComposeViewController canSendText])
    {
        MFMessageComposeViewController*controller=[[MFMessageComposeViewController alloc]init];
        controller.recipients=phones;
        controller.navigationBar.tintColor=[UIColor redColor];
        controller.body=body;
        controller.messageComposeDelegate=self;
        [self presentViewController:controller animated:YES completion:nil];
        
        [[[[controller viewControllers]lastObject]navigationItem]setTitle:title];//修改短信界面标题
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示信息"
                                                   message:@"该设备不支持短信功能"
                                                  delegate:nil
                                         cancelButtonTitle:@"确定"
                                         otherButtonTitles:nil,nil];
        [alert show];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
